import { getMenuList } from '../../api/user'
const state = {
    // 用户菜单
    menuRouters:{},
    // 菜单
    menuList:[]
}

const actions = {
    // 保存菜单数据
    saveMenuList(context,menuList){
        // 将数据放到vuex
        context.commit('SET_MENUROUTERS',menuList);
    },
    // 获取菜单数据
    async getMenuList(context){
        // 发请求获取
        const result = await getMenuList();
        const {code,data} = result;
        if (code === 200){
            context.commit('SET_MENUROUTERS',data);
        }
    }
}

const mutations ={
    // 设置菜单路由
    SET_MENUROUTERS(state,value){
        state.menuRouters = value;
        state.menuList = value.menuList;
    }
}

const getters = {

}

export default {
    state,
    actions,
    mutations,
    getters
}
